package com.ygxsk.carhome.ui.signature;

import android.Manifest;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.afollestad.materialdialogs.MaterialDialog;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.ALog;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.ClickUtils;
import com.blankj.utilcode.util.ColorUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.PathUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.flyco.roundview.RoundTextView;
import com.gyf.immersionbar.ImmersionBar;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.XXPermissions;
import com.hjq.toast.Toaster;
import com.kathline.library.content.ZFileConfiguration;
import com.kathline.library.content.ZFileContent;
import com.kongzue.dialogx.dialogs.PopTip;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.util.SmartGlideImageLoader;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.wildma.idcardcamera.camera.IDCardCamera;
import com.yalantis.ucrop.UCrop;
import com.yanzhenjie.album.Action;
import com.yanzhenjie.album.Album;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.runtime.Permission;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.alertview.AlertView;
import com.ygxsk.carhome.alertview.OnItemClickListener;
import com.ygxsk.carhome.constant.ConstantApi;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.constant.ExtraKey;
import com.ygxsk.carhome.constant.ExtraValue;
import com.ygxsk.carhome.enumwrap.SignatureClientType;
import com.ygxsk.carhome.enumwrap.SignatureVehicleType;
import com.ygxsk.carhome.event.EventSignatureMain;
import com.ygxsk.carhome.listener.AuthorityCallbackListener;
import com.ygxsk.carhome.listener.Delivery;
import com.ygxsk.carhome.listener.ErrorParentExtraSingle;
import com.ygxsk.carhome.permission.PermissionSetting;
import com.ygxsk.carhome.permission.RuntimeRationale;
import com.ygxsk.carhome.response.FileSignatureManage;
import com.ygxsk.carhome.response.IdCardInfo;
import com.ygxsk.carhome.retrofit.AddLogUpLoadInfo;
import com.ygxsk.carhome.retrofit.ApiException;
import com.ygxsk.carhome.retrofit.ApiRequestSubListener;
import com.ygxsk.carhome.retrofit.ApiService;
import com.ygxsk.carhome.retrofit.ErrorConsumer;
import com.ygxsk.carhome.retrofit.GoogleService;
import com.ygxsk.carhome.retrofit.NetworkManager;
import com.ygxsk.carhome.retrofit.ResponseTransformer;
import com.ygxsk.carhome.sys.PermissionInterceptor;
import com.ygxsk.carhome.sys.PermissionNameConvert;
import com.ygxsk.carhome.ui.ErrorActivity;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.utils.TimeUtilSer;
import com.ygxsk.carhome.utils.ViewUitls;
import com.ygxsk.carhome.views.ClearEditText;
import com.ygxsk.integrated.retrofit.Parameterkey;

import org.greenrobot.eventbus.EventBus;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerActivity;
import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerPreviewActivity;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Retrofit;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-11-22  11:16
 * @Description:填充客户信息的内容
 */
public class InputCustomerActivity extends ErrorActivity implements EasyPermissions.PermissionCallbacks, ErrorParentExtraSingle {

    private static final int PRC_PHOTO_PICKER = 1;
    private static final int RC_CHOOSE_PHOTO = 1;

    @Override
    public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
        //
    }

    @Override
    public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
        if (requestCode == PRC_PHOTO_PICKER) {
            Toast.makeText(this, getResources().getString(R.string.imageselectstr), Toast.LENGTH_SHORT).show();
        }
    }

    @AfterPermissionGranted(PRC_PHOTO_PICKER)
    private void choicePhotoWrapper() {

        String[] perms = null;

//        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
        perms = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
//        } else {
//            perms = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
//        }

        if (EasyPermissions.hasPermissions(this, perms)) {

            photoPicker();

        } else {
//            EasyPermissions.requestPermissions(this, "图片选择需要以下权限:\n\n1.访问设备上的照片\n\n2.拍照", PRC_PHOTO_PICKER, perms);
            EasyPermissions.requestPermissions(this, getResources().getString(R.string.imageselectstr), PRC_PHOTO_PICKER, perms);

        }

    }

    private void photoPicker() {

        // 拍照后照片的存放目录，改成你自己拍照后要存放照片的目录。如果不传递该参数的话就没有拍照功能
//            File takePhotoDir = new File(Environment.getExternalStorageDirectory(), "BGAPhotoPickerTakePhoto");
        File takePhotoDir = new File(PathUtils.getExternalAppFilesPath(), ConstantSign.BGA_PHOTO_PICKER_TAKEPHOTO);

        Intent photoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this)
//                    .cameraFileDir(mTakePhotoCb.isChecked() ? takePhotoDir : null) // 拍照后照片的存放目录，改成你自己拍照后要存放照片的目录。如果不传递该参数的话则不开启图库里的拍照功能
                .cameraFileDir(takePhotoDir) // 拍照后照片的存放目录，改成你自己拍照后要存放照片的目录。如果不传递该参数的话则不开启图库里的拍照功能
                .maxChooseCount(1) // 图片选择张数的最大值
                .selectedPhotos(null) // 当前已选中的图片路径集合
                .pauseOnScroll(false) // 滚动列表时是否暂停加载图片
                .build();

        startActivityForResult(photoPickerIntent, RC_CHOOSE_PHOTO);

    }


    private void choicePhotoWrapperXXPermissions() {

        if (!XXPermissions.isGranted(InputCustomerActivity.this, com.hjq.permissions.Permission.READ_MEDIA_IMAGES)) {

            CommUtils.checkMaterialDialog(materialDialog);

            materialDialog = CommUtils.authorityRequest(mActivityInstance, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_ALBUM, new AuthorityCallbackListener() {
                @Override
                public void doSomeThing() {

                    CommUtils.checkMaterialDialog(materialDialog);

                    XXPermissions.with(InputCustomerActivity.this)
                            // 适配分区存储应该这样写
                            //.permission(Permission.Group.STORAGE)
                            // 不适配分区存储应该这样写
//                    .permission(com.hjq.permissions.Permission.CAMERA)//
                            .permission(com.hjq.permissions.Permission.READ_MEDIA_IMAGES)//
//                                    .permission(com.hjq.permissions.Permission.READ_MEDIA_VIDEO)//
//                                    .permission(com.hjq.permissions.Permission.READ_MEDIA_AUDIO)//
                            //).permission(com.hjq.permissions.Permission.MANAGE_EXTERNAL_STORAGE
//                                                        .interceptor(new PermissionInterceptor())
                            .request(new OnPermissionCallback() {

                                @Override
                                public void onGranted(@NonNull List<String> permissions, boolean allGranted) {

                                    if (!allGranted) {
                                        // TODO: 2024/1/23 18:50 权限这里要不要给提示？权限没通过

                                        return;
                                    }

                                    Toaster.show(String.format(getString(R.string.demo_obtain_permission_success_hint),
                                            PermissionNameConvert.getPermissionString(InputCustomerActivity.this, permissions)));

                                    photoPicker();

                                }
                            });

                }
            });

        } else {

            photoPicker();

        }

    }


    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }


    private FileSignatureManage extra_signature_fileSignatureManage;


    interface PicCallBackInSignature {

        void clickCamera(int position);

        void clickAlbum(int position);

    }

    //合同类别
    @BindView(R.id.radiogroupvehicletype)
    RadioGroup radioGroupVehicleType;

    //是新车类型
    @BindView(R.id.radiobuttonvehicletypecarnew)
    RadioButton radioButtonVehicleTypeCarNew;

    //是二手车类型
    @BindView(R.id.radiobuttonvehicletypecarold)
    RadioButton radioButtonVehicleTypeCarOld;


    //客户的类型
    @BindView(R.id.radiogroupcustomertype)
    RadioGroup radioGroupCustomerType;

    //个人类型
    @BindView(R.id.radiobuttoncustomertypeperson)
    RadioButton radioButtonCustomerTypePerson;

    //企业类型
    @BindView(R.id.radiobuttoncustomertypecompany)
    RadioButton radioButtonCustomerTypeCompany;

    //客户姓名
    @BindView(R.id.editviewcustomername)
    ClearEditText editViewCustomerName;

    //客户身份证号
    @BindView(R.id.editviewidcard)
    ClearEditText editViewIdCard;

    //客户手机号
    @BindView(R.id.editviewphoneevaluate)
    ClearEditText editViewPhoneEvaluate;

    //短信认证
//    @BindView(R.id.textviewsignaturesmscreate)
//    RoundTextView textViewCardSmsCreate;

    //生成认证二维码
    @BindView(R.id.textviewtosignatureqrcodecreate)
    RoundTextView textViewToSignatureQRCodeCreate;

    //发送短信链接到客户手机
    @BindView(R.id.textviewtosignaturelinkscreate)
    RoundTextView textViewToSignatureLinksCreate;

    //选中拍照
//    @BindView(R.id.layoutbuttoncardplaycard)
//    RoundTextView layoutButtonCardPlay;

    //图片内容
    @BindView(R.id.imageviewidcardinfoinside)
    ImageView imageViewIdCardInfo;

    @BindView(R.id.textviewhelpbottomhight)
    TextView textViewHelpBottomHight;

    //客户类型   客户类型(0:个人;1:企业),默认是个人,默认是个人
    private String clientType_upLoad = "0";
    //合同的类别  新车  二手车 ？
    private String archiveTypeId_upLoad;
    //客户手机号内容
    private String clientPhone_upLoad;

    //客户姓名的上传
    private String clientName_upLoad;

    //客户身份证上传
    private String idCard_upLoad;

    private MaterialDialog materialDialogCustomView;

    //该下载apk任务的任务id值内容；
    private long taskDownLoadApkId;

    private PermissionSetting mSetting;


    private PicCallBackInSignature picCallBackListener = new PicCallBackInSignature() {

        @Override
        public void clickCamera(int position) {

            //调用相机拍照
            //methodPicCallBackCamera();

            IDCardCamera.create(InputCustomerActivity.this).openCamera(IDCardCamera.TYPE_IDCARD_FRONT);

        }

        @Override
        public void clickAlbum(int position) {

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {

                choicePhotoWrapper();

            } else {

                choicePhotoWrapperXXPermissions();

            }

        }

    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mActivityInstance = this;

        mSetting = new PermissionSetting(this);

        processExtraData();

        initViews();

//        gainDatas();

        //注册一个下载,主要是下载二维码的图片内容
        Aria.download(this).register();

    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_input_customer;
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();

        ImmersionBar.with(this)//
                .titleBar(R.id.toolbarygxskout)
                .fitsSystemWindows(true)//解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                //.statusBarColor(R.color.colorPrimary)//
                //.navigationBarColor(R.color.colorPrimary)//
                //.keyboardEnable(true)
                .init();

    }

    @Override
    protected void initToolBar(ToolbarHelper toolbarHelper) {

        toolbarHelper.setTitle(getString(R.string.title_signature_message_input));
        toolbarHelper.setVersionName(true, AppUtils.getAppVersionName());
        toolbarHelper.setLayoutClose(false, "", null);
        toolbarHelper.setLayoutLeft(true, R.drawable.backicon, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //搜索客户信息，优先关闭软键盘
                KeyboardUtils.hideSoftInput(mActivityInstance);
                methodBack();
            }
        });


        toolbarHelper.setLayoutRight(false, 0, "", null);

        //添加 新的签约 按钮
//        toolbarHelper.setLayoutRight(true, 1, "历史记录", new ClickUtils.OnDebouncingClickListener() {
//
//            @Override
//            public void onDebouncingClick(View v) {
//
//                //快速双加的限制，
//                Bundle extra_bundle = new Bundle();
//                ActivityUtils.startActivity(extra_bundle, SignatureSumHistoryActivity.class);
//
//            }
//        });

    }

    @Override
    protected void onClickNodata(View v) {

    }

    @Override
    protected void initViews() {

        //合同类型 默认是新车
        archiveTypeId_upLoad = SignatureVehicleType.VEHICLETYPE_CAR_NEW.getIndex();
        //默认的类型是 个人类型
        clientType_upLoad = SignatureClientType.CLIENTTYPE_PERSON.getIndex();

        //如果是从【新建合同】过来的，那么需要填充电话信息；
        if (flag_jumpfrom_where == ExtraValue.VALUE_JUMP_FORM_SIGNATRUE_ADDSUBMIT_TO_ACTIVITY) {

            Delivery.getInstance().post(new Runnable() {
                @Override
                public void run() {
                    if (editViewPhoneEvaluate != null) {
                        editViewPhoneEvaluate.setText(clientPhone_upLoad);
                    }
                }
            });

        }

        //底部一个帮助布局的高度
        CommUtils.methodHelpView4(textViewHelpBottomHight);

        if (imageViewIdCardInfo != null) {

            imageViewIdCardInfo.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (mAlertView != null && mAlertView.isShowing()) {
                        mAlertView.dismiss();
                        mAlertView = null;
                    }

                    //第二种方式：
                    AlertView.Builder builder = new AlertView.Builder().setContext(InputCustomerActivity.this)
                            .setStyle(AlertView.Style.ActionSheet)
                            .setTitle(getResources().getString(R.string.upload_idcard))
                            .setMessage(null)
                            .setCancelText(getResources().getString(R.string.alert_cancel))//取消
                            .setOthers(new String[]{//
                                    getResources().getString(R.string.upload_idcard_takephoto),//拍照
                                    getResources().getString(R.string.upload_idcard_pickphoto)})//相册选择
                            .setOnItemClickListener(new OnItemClickListener() {
                                @Override
                                public void onItemClick(Object o, int position) {

                                    if (position == 0) {

                                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {

                                            if (!AndPermission.hasPermissions(mActivityInstance, Permission.CAMERA)) {

                                                CommUtils.checkMaterialDialog(materialDialog);

                                                materialDialog = CommUtils.authorityRequest(mActivityInstance, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_CAMERA, new AuthorityCallbackListener() {
                                                    @Override
                                                    public void doSomeThing() {

                                                        CommUtils.checkMaterialDialog(materialDialog);

                                                        AndPermission.with(InputCustomerActivity.this)//
                                                                .runtime()//
                                                                .permission(Permission.CAMERA)//
                                                                .rationale(new RuntimeRationale())
                                                                .onGranted(new com.yanzhenjie.permission.Action<List<String>>() {
                                                                    @Override
                                                                    public void onAction(List<String> permissions) {

                                                                        if (picCallBackListener != null) {
                                                                            picCallBackListener.clickCamera(0);
                                                                        }

                                                                    }
                                                                }).onDenied(new com.yanzhenjie.permission.Action<List<String>>() {
                                                                    @Override
                                                                    public void onAction(List<String> permissions) {

                                                                        ToastUtils.showShort(ConstantSign.NEEDPERMISS_PHONE);

                                                                        if (AndPermission.hasAlwaysDeniedPermission(InputCustomerActivity.this, permissions)) {
                                                                            mSetting.showSetting(ConstantApi.PERMISSION_NORMAL, InputCustomerActivity.this, permissions);
                                                                        }

                                                                    }
                                                                }).start();

                                                    }
                                                });

                                            } else {

                                                if (picCallBackListener != null) {
                                                    picCallBackListener.clickCamera(0);
                                                }

                                            }


                                        } else {

                                            if (!XXPermissions.isGranted(mActivityInstance, com.hjq.permissions.Permission.CAMERA)) {

                                                CommUtils.checkMaterialDialog(materialDialog);

                                                materialDialog = CommUtils.authorityRequest(InputCustomerActivity.this, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_CAMERA, new AuthorityCallbackListener() {
                                                    @Override
                                                    public void doSomeThing() {

                                                        CommUtils.checkMaterialDialog(materialDialog);

                                                        XXPermissions.with(InputCustomerActivity.this)
                                                                // 适配分区存储应该这样写
                                                                //.permission(Permission.Group.STORAGE)
                                                                // 不适配分区存储应该这样写
                                                                .permission(com.hjq.permissions.Permission.CAMERA)//
//                                                    .permission(Permission.READ_MEDIA_IMAGES)//
//                                                    .permission(Permission.READ_MEDIA_VIDEO)//
//                                                    .permission(Permission.READ_MEDIA_AUDIO)//
                                                                //).permission(com.hjq.permissions.Permission.MANAGE_EXTERNAL_STORAGE
//                                                        .interceptor(new PermissionInterceptor())
                                                                .request(new OnPermissionCallback() {

                                                                    @Override
                                                                    public void onGranted(@NonNull List<String> permissions, boolean allGranted) {

                                                                        if (!allGranted) {
                                                                            return;
                                                                        }

                                                                        Toaster.show(String.format(getString(R.string.demo_obtain_permission_success_hint),
                                                                                PermissionNameConvert.getPermissionString(InputCustomerActivity.this, permissions)));

                                                                        if (picCallBackListener != null) {
                                                                            picCallBackListener.clickCamera(0);
                                                                        }

                                                                    }
                                                                });
                                                    }
                                                });

                                            } else {

                                                if (picCallBackListener != null) {
                                                    picCallBackListener.clickCamera(0);
                                                }

                                            }

                                        }

                                    } else if (position == 1) {

                                        //如果是android13手机 那么只需要判断一个读取权限即可

                                        if (picCallBackListener != null) {
                                            picCallBackListener.clickAlbum(1);
                                        }

//                                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
//
//
//                                            if (!AndPermission.hasPermissions(mActivityInstance, Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE)) {
//
//                                                CommUtils.authorityRequest(mActivityInstance, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_ALBUM, new AuthorityCallbackListener() {
//                                                    @Override
//                                                    public void doSomeThing() {
//
//                                                        //基本上可以确认这个权限弹窗 是没问题的。
//                                                        AndPermission.with(InputCustomerActivity.this)
//                                                                .runtime()//
//                                                                .permission(
//                                                                        Permission.READ_EXTERNAL_STORAGE,//
//                                                                        Permission.WRITE_EXTERNAL_STORAGE)//
//                                                                .rationale(new RuntimeRationale())
//                                                                .onGranted(new com.yanzhenjie.permission.Action<List<String>>() {
//                                                                    @Override
//                                                                    public void onAction(List<String> permissions) {
//
//                                                                        if (picCallBackListener != null) {
//                                                                            picCallBackListener.clickAlbum(1);
//                                                                        }
//
//                                                                    }
//                                                                }).onDenied(new com.yanzhenjie.permission.Action<List<String>>() {
//                                                                    @Override
//                                                                    public void onAction(List<String> permissions) {
//
//                                                                        ToastUtils.showShort(ConstantSign.NEEDPERMISS_PHONE);
//
//                                                                        if (AndPermission.hasAlwaysDeniedPermission(InputCustomerActivity.this, permissions)) {
//                                                                            mSetting.showSetting(ConstantApi.PERMISSION_NORMAL, InputCustomerActivity.this, permissions);
//                                                                        }
//
//                                                                    }
//                                                                }).start();
//
//                                                    }
//                                                });
//
//                                            } else {
//
//                                                if (picCallBackListener != null) {
//                                                    picCallBackListener.clickAlbum(1);
//                                                }
//
//                                            }

//                                        } else {

//                                            if (!AndPermission.hasPermissions(mActivityInstance, Permission.READ_EXTERNAL_STORAGE)) {
//
//                                                CommUtils.authorityRequest(mActivityInstance, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_ALBUM, new AuthorityCallbackListener() {
//                                                    @Override
//                                                    public void doSomeThing() {
//
//                                                        //基本上可以确认这个权限弹窗 是没问题的。
//                                                        AndPermission.with(InputCustomerActivity.this)
//                                                                .runtime()//
//                                                                .permission(Permission.READ_EXTERNAL_STORAGE)//
//                                                                .rationale(new RuntimeRationale())
//                                                                .onGranted(new com.yanzhenjie.permission.Action<List<String>>() {
//                                                                    @Override
//                                                                    public void onAction(List<String> permissions) {
//
//                                                                        if (picCallBackListener != null) {
//                                                                            picCallBackListener.clickAlbum(1);
//                                                                        }
//
//                                                                    }
//                                                                }).onDenied(new com.yanzhenjie.permission.Action<List<String>>() {
//                                                                    @Override
//                                                                    public void onAction(List<String> permissions) {
//
//                                                                        ToastUtils.showShort(ConstantSign.NEEDPERMISS_PHONE);
//
//                                                                        if (AndPermission.hasAlwaysDeniedPermission(InputCustomerActivity.this, permissions)) {
//                                                                            mSetting.showSetting(ConstantApi.PERMISSION_NORMAL, InputCustomerActivity.this, permissions);
//                                                                        }
//
//                                                                    }
//                                                                }).start();
//
//                                                    }
//                                                });
//
//                                            } else {
//
//                                                if (picCallBackListener != null) {
//                                                    picCallBackListener.clickAlbum(1);
//                                                }
//
//                                            }
//
//                                        }

                                    }


                                }
                            });

                    mAlertView = builder.build();
                    mAlertView.setCancelable(false);
                    mAlertView.show();

                }
            });
        }

        //个人用户或者企业用户
        radioGroupCustomerType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {

//                    public enum SignatureClientType {
//                        //客户类型(0:个人;1:企业),默认是个人
//                        CLIENTTYPE_PERSON("0"),
//                        CLIENTTYPE_COMPANY("1");

                if (checkedId == R.id.radiobuttoncustomertypeperson) {

                    //客户类型(0:个人;1:企业),默认是个人
                    clientType_upLoad = SignatureClientType.CLIENTTYPE_PERSON.getIndex();

                } else if (checkedId == R.id.radiobuttoncustomertypecompany) {

                    clientType_upLoad = SignatureClientType.CLIENTTYPE_COMPANY.getIndex();

                }


            }
        });


        //合同类型 是新车或者是二手车
        radioGroupVehicleType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {

//                    public enum SignatureVehicleType {
//                        //车辆类型  1新车  2二手车
//                        VEHICLETYPE_CAR_NEW("1"),
//                        VEHICLETYPE_CAR_OLD("2");

                if (checkedId == R.id.radiobuttonvehicletypecarnew) {

                    archiveTypeId_upLoad = SignatureVehicleType.VEHICLETYPE_CAR_NEW.getIndex();

                } else if (checkedId == R.id.radiobuttonvehicletypecarold) {

                    archiveTypeId_upLoad = SignatureVehicleType.VEHICLETYPE_CAR_OLD.getIndex();
                }

            }
        });


//        if (textViewCardCancel != null) {
//            textViewCardCancel.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
//                @Override
//                public void onDebouncingClick(View v) {
//
//                    //此时 弹窗是已经被弹出的
//                    if (materialDialogCustomView != null) {
//                        materialDialogCustomView.dismiss();
//                    }
//
//                    //直接关闭该页面整体的,因为不认证是没法儿用的
//                    //methodBack();
//
//                }
//            });
//        }


        if (textViewToSignatureQRCodeCreate != null) {

            textViewToSignatureQRCodeCreate.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
                @Override
                public void onDebouncingClick(View v) {

                    //打开浏览器的逻辑，是不可行的，放弃；因为交互信息 后台无法给到手机端
                    //CommUtils.linkJumpDialogSignature(SignatureActivity.this, SignatureActivity.this, _contentResult);
                    //应该是打开内部的webView才可以；可以实现法大大给认证结果给H5，下一步Android和H5交互,这样手机端才知道认证成功；
//                  ViewUitls.method_toWebView_signature(getString(R.string.title_dialog_signature), _contentResult);

                    clientPhone_upLoad = editViewPhoneEvaluate.getText().toString().trim();
                    clientName_upLoad = editViewCustomerName.getText().toString().trim();
                    idCard_upLoad = editViewIdCard.getText().toString().trim();

                    // TODO: 2023-10-26 16:39 校验为空的手机号为空的
                    if (TextUtils.isEmpty(clientPhone_upLoad)) {

                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getResources().getString(R.string.hint_input_phone), true);
                        mAlertView.show();

//                            PopTip.show(getResources().getString(R.string.hint_input_phone)).iconWarning();

//                        new MaterialDialog.Builder(mActivityInstance)
//                                .title(ConstantSign.ALERT_TITLE)
//                                .titleGravity(GravityEnum.CENTER)
//                                .content(getResources().getString(R.string.hint_input_phone))
//                                .contentGravity(GravityEnum.CENTER)
//                                .positiveText(getResources().getString(R.string.popubuttonclose))
//                                //.negativeText("取消")
//                                .show();

//                            TipDialog.show(getResources().getString(R.string.hint_input_phone), WaitDialog.TYPE.ERROR);

                        return;
                    }


                    //校验客户姓名
                    if (TextUtils.isEmpty(clientName_upLoad)) {

                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getResources().getString(R.string.hint_input_custome_name), true);
                        mAlertView.show();

//                            PopTip.show(getResources().getString(R.string.hint_input_phone)).iconWarning();

//                        new MaterialDialog.Builder(mActivityInstance)
//                                .title(ConstantSign.ALERT_TITLE)
//                                .titleGravity(GravityEnum.CENTER)
//                                .content(getResources().getString(R.string.hint_input_phone))
//                                .contentGravity(GravityEnum.CENTER)
//                                .positiveText(getResources().getString(R.string.popubuttonclose))
//                                //.negativeText("取消")
//                                .show();

//                            TipDialog.show(getResources().getString(R.string.hint_input_phone), WaitDialog.TYPE.ERROR);

                        return;
                    }

                    //校验客户身份证号码？是否要校验身份证号码的正确性 ？
                    if (TextUtils.isEmpty(idCard_upLoad)) {

                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getResources().getString(R.string.hint_input_idcard), true);
                        mAlertView.show();

//                            PopTip.show(getResources().getString(R.string.hint_input_phone)).iconWarning();

//                        new MaterialDialog.Builder(mActivityInstance)
//                                .title(ConstantSign.ALERT_TITLE)
//                                .titleGravity(GravityEnum.CENTER)
//                                .content(getResources().getString(R.string.hint_input_phone))
//                                .contentGravity(GravityEnum.CENTER)
//                                .positiveText(getResources().getString(R.string.popubuttonclose))
//                                //.negativeText("取消")
//                                .show();

//                            TipDialog.show(getResources().getString(R.string.hint_input_phone), WaitDialog.TYPE.ERROR);

                        return;
                    }

                    //选择客户类型
                    if (TextUtils.isEmpty(clientType_upLoad)) {

                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getResources().getString(R.string.dialog_select_clienttype), true);
                        mAlertView.show();

//                            PopTip.show(getResources().getString(R.string.dialog_select_clienttype)).iconWarning();

//                        new MaterialDialog.Builder(mActivityInstance)
//                                .title(ConstantSign.ALERT_TITLE)
//                                .titleGravity(GravityEnum.CENTER)
//                                .content(getResources().getString(R.string.dialog_select_clienttype))
//                                .contentGravity(GravityEnum.CENTER)
//                                .positiveText(getResources().getString(R.string.popubuttonclose))
//                                //.negativeText("取消")
//                                .show();

//                            TipDialog.show(getResources().getString(R.string.dialog_select_clienttype), WaitDialog.TYPE.ERROR);

                        return;
                    }

                    //选择合同类别
                    if (TextUtils.isEmpty(archiveTypeId_upLoad)) {

                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getResources().getString(R.string.dialog_select_archivetypeId), true);
                        mAlertView.show();

//                            PopTip.show(getResources().getString(R.string.dialog_select_archivetypeId)).iconWarning();

//                        new MaterialDialog.Builder(mActivityInstance)
//                                .title(ConstantSign.ALERT_TITLE)
//                                .titleGravity(GravityEnum.CENTER)
//                                .content(getResources().getString(R.string.dialog_select_archivetypeId))
//                                .contentGravity(GravityEnum.CENTER)
//                                .positiveText(getResources().getString(R.string.popubuttonclose))
//                                //.negativeText("取消")
//                                .show();

//                            TipDialog.show(getResources().getString(R.string.dialog_select_archivetypeId), WaitDialog.TYPE.ERROR);

                        return;
                    }

                    //信息都填写完毕，提交，关闭该弹窗
//                    if (materialDialogCustomView != null) {
//                        materialDialogCustomView.dismiss();
//                    }

                    //生成客户认证二维码，如果是陌生用户，可能没认证过，有弹窗，如果是老客户，已经认证过，那么就不弹出，直接跳转到添加合同页面
                    gain_create_signature();

                }
            });
        }


        //认证链接
        if (textViewToSignatureLinksCreate != null) {

            textViewToSignatureLinksCreate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    //发送认证链接
                    clientPhone_upLoad = editViewPhoneEvaluate.getText().toString().trim();
                    clientName_upLoad = editViewCustomerName.getText().toString().trim();
                    idCard_upLoad = editViewIdCard.getText().toString().trim();

                    // 2023-10-26 16:39 校验为空的手机号为空的
                    if (TextUtils.isEmpty(clientPhone_upLoad)) {

                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getResources().getString(R.string.hint_input_phone), true);
                        mAlertView.show();

//                            PopTip.show(getResources().getString(R.string.hint_input_phone)).iconWarning();

//                        new MaterialDialog.Builder(mActivityInstance)
//                                .title(ConstantSign.ALERT_TITLE)
//                                .titleGravity(GravityEnum.CENTER)
//                                .content(getResources().getString(R.string.hint_input_phone))
//                                .contentGravity(GravityEnum.CENTER)
//                                .positiveText(getResources().getString(R.string.popubuttonclose))
//                                //.negativeText("取消")
//                                .show();

//                            TipDialog.show(getResources().getString(R.string.hint_input_phone), WaitDialog.TYPE.ERROR);

                        return;
                    }

                    //校验客户姓名
                    if (TextUtils.isEmpty(clientName_upLoad)) {
                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getResources().getString(R.string.hint_input_custome_name), true);
                        mAlertView.show();
                        return;
                    }

                    //校验客户身份证号码？是否要校验身份证号码的正确性 ？
                    if (TextUtils.isEmpty(idCard_upLoad)) {
                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getResources().getString(R.string.hint_input_idcard), true);
                        mAlertView.show();
                        return;
                    }

                    //选择客户类型
                    if (TextUtils.isEmpty(clientType_upLoad)) {

                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getResources().getString(R.string.dialog_select_clienttype), true);
                        mAlertView.show();

//                            PopTip.show(getResources().getString(R.string.dialog_select_clienttype)).iconWarning();

//                        new MaterialDialog.Builder(mActivityInstance)
//                                .title(ConstantSign.ALERT_TITLE)
//                                .titleGravity(GravityEnum.CENTER)
//                                .content(getResources().getString(R.string.dialog_select_clienttype))
//                                .contentGravity(GravityEnum.CENTER)
//                                .positiveText(getResources().getString(R.string.popubuttonclose))
//                                //.negativeText("取消")
//                                .show();

//                            TipDialog.show(getResources().getString(R.string.dialog_select_clienttype), WaitDialog.TYPE.ERROR);

                        return;
                    }

                    //选择合同类别
                    if (TextUtils.isEmpty(archiveTypeId_upLoad)) {
                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getResources().getString(R.string.dialog_select_archivetypeId), true);
                        mAlertView.show();

//                            PopTip.show(getResources().getString(R.string.dialog_select_archivetypeId)).iconWarning();

//                        new MaterialDialog.Builder(mActivityInstance)
//                                .title(ConstantSign.ALERT_TITLE)
//                                .titleGravity(GravityEnum.CENTER)
//                                .content(getResources().getString(R.string.dialog_select_archivetypeId))
//                                .contentGravity(GravityEnum.CENTER)
//                                .positiveText(getResources().getString(R.string.popubuttonclose))
//                                //.negativeText("取消")
//                                .show();

//                            TipDialog.show(getResources().getString(R.string.dialog_select_archivetypeId), WaitDialog.TYPE.ERROR);

                        return;
                    }

                    //信息都填写完毕，提交，关闭该弹窗
//                    if (materialDialogCustomView != null) {
//                        materialDialogCustomView.dismiss();
//                    }

                    //发送认证链接到客户手机
                    gain_send_signature_links_to_customer();

                }
            });
        }


    }


    //发起签约,的生成认证二维码，给客户扫码 填写客户自己的认证
    //生成客户认证二维码，如果是陌生用户，可能没认证过，有弹窗，如果是老客户，已经认证过，那么就不弹出，直接跳转到添加合同页面
    private void gain_create_signature() {

        clientPhone_upLoad = editViewPhoneEvaluate.getText().toString().trim();
        clientName_upLoad = editViewCustomerName.getText().toString().trim();
        idCard_upLoad = editViewIdCard.getText().toString().trim();

        if (NetworkUtils.isConnected()) {

            HashMap<String, Object> map = new HashMap<>();
            map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());//,
            map.put(Parameterkey.clientPhone, clientPhone_upLoad);//,客户手机号
            map.put(Parameterkey.clientName, clientName_upLoad);//客户姓名
            map.put(Parameterkey.idCard, idCard_upLoad);//客户身份证信息

            map.put(Parameterkey.clientType, clientType_upLoad);//,clientType 客户类型(0:个人;1:企业),默认是个人
            map.put(Parameterkey.archiveTypeId, archiveTypeId_upLoad);//档案的类型，是新车 还是二手车

            AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
            addLogUpLoadInfo.setActivity(mActivityInstance);
            addLogUpLoadInfo.setWhat(ConstantApi.WHAT_CHECKOPENFASC_URL);//请求数字标识
            addLogUpLoadInfo.setUrlPath(ApiService.checkOpenFasc_url);//url地址
            addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
            addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
            addLogUpLoadInfo.setHashMapParameter(map);

            NetworkManager.getInstance().initRetrofitRxJava()
                    .create(ApiService.class)
                    .getFascAuthQr(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                            MediaType.parse(ApiService.HEADER_JSON)))
                    .compose(InputCustomerActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                    .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<SignatureWebInformationBean>() {
                        @Override
                        public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                            super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);
                            //{"data":"","message":"无更多数据","code":"29999"}
                            CommUtils.checkMaterialDialog(materialDialog);

                            //这里要不要给提示？无更多数据
                            if (!TextUtils.isEmpty(serverMessage)) {
                                ToastUtils.showShort(serverMessage);
                            }

                        }
                    })).doOnSubscribe(new Consumer<Disposable>() {
                        @Override
                        public void accept(Disposable disposable) throws Throwable {
                            method_create_materialDialog(mActivityInstance, ConstantSign.TIPS_SUBMIT);
                        }
                    }).subscribe(new Consumer<SignatureWebInformationBean>() {
                        @Override
                        public void accept(SignatureWebInformationBean signatureWebInformationBean) throws Throwable {

//                            {
//                                "code": "20000",
//                                    "data": {
//                                   "authUrl": "https://80000333.uat-e.fadada.com/authorizeui/person/login?authSerial=2dedef36d279452d82ed3cadb1d2dd7f", //法大大认证连接
//                                        "qrUrl": "http://222.222.17.184:8990/resource/15144218047-1499.jpg", //认证二维码图片地址
//                                        "informationId": 2 //合同档案ID
//                            },
//                                "message": "success"
//                            }


                            //真实接口
//                            {
//                                "code":"20000",
//                                        "data":{
//                                        "authUrl":"https://80000333.uat-e.fadada.com/authorizeui/person/login?authSerial=59e8e4a8223640659f64a056dbf3334a",
//                                        "qrUrl":"http://222.222.17.184:8990/resource/17531108969-1495认证二维码.jpg",
//                                        "informationId":3
//                            },
//                                "message":"success"
//                            }

                            CommUtils.checkMaterialDialog(materialDialog);

                            // TODO: 2023-10-26 18:25 存入本地 做接口携带用到；
                            //存入 informationId 的值内容；
                            String informationId = signatureWebInformationBean.getInformationId();
                            mSession.setInformationId(informationId);

                            //MMKV.defaultMMKV().encode(ConstantSign.P_INFORMATIONID, informationId);

                            //链接的地址信息
                            String authUrl = signatureWebInformationBean.getAuthUrl();

                            // TODO: 2023-10-26 18:24  获取到二维码链接  怎么用呢？
                            //二维码的地址信息  ?怎么用呢？
                            String qrUrl = signatureWebInformationBean.getQrUrl();

                            //获取这个客户是否已经开通过法大大
                            boolean fascAuth = signatureWebInformationBean.getFascAuth();

//                            if (!TextUtils.isEmpty(informationId)) {
//                                //怎么用？
//                            }

                            //如果用户已经开通过法大大，那么，提示，并跳转到档案盒子，添加
                            if (fascAuth) {

                                PopTip.show(getResources().getString(R.string.send_links_to_hasqrcode)).iconSuccess();

                                //客户已经认证过法大大认证，请新建合同；
                                method_show_QRCode_dialog_customer_has_signature(signatureWebInformationBean);

                            } else {

                                //如果没有开通过法大大，那么
                                if (!TextUtils.isEmpty(qrUrl)) {

                                    PopTip.show(getResources().getString(R.string.send_links_to_qrcode)).iconSuccess();

                                    method_show_QRCode_dialog(qrUrl);

                                }
                            }

                        }
                    }, new ErrorConsumer() {

                        @Override
                        protected void error(ApiException apiException) {

                            CommUtils.checkMaterialDialog(materialDialog);

                            //页面报错；给提示
                            if (apiException != null) {
                                ToastUtils.showShort(apiException.getDisplayMessage());
                            }

                        }
                    });

        } else {

            ToastUtils.showShort(StringUtils.getString(R.string.http_exception_network));

        }


    }


    //弹窗的操作：展示获取到的优惠券的信息；
    private void method_show_QRCode_dialog(String _imageUrl) {

        View viewCard = View.inflate(mActivityInstance, R.layout.qrcodemiddlepopu, null);

        if (viewCard != null) {

            //暂时没有标题？
            TextView textViewQrName = (TextView) viewCard.findViewById(R.id.textviewqrname);
            //弹窗的标题内容
            TextView textNamePopu = (TextView) viewCard.findViewById(R.id.tv_namepopu);
            textNamePopu.setText("认证二维码");

            //填充房间号的名称内容
//          textViewQrName.setText(_siteNo);

            //图片的内容  imageviewpaintbookingqrcode
            ImageView imageViewQRCode = (ImageView) viewCard.findViewById(R.id.imageviewpaintbookingqrcode);
            //关闭 按钮
            RoundTextView textViewCardCancel = (RoundTextView) viewCard.findViewById(R.id.textviewqrcodecancel);
            //保存为图片的按钮
            RoundTextView textViewCardSure = (RoundTextView) viewCard.findViewById(R.id.textviewqrcodesave);
            //友盟分享的内容
//           RoundTextView textViewQrcodeShare = (RoundTextView) viewCard.findViewById(R.id.textViewQrcodeShare);
//
            String imagePathFolder = PathUtils.getExternalAppFilesPath() + File.separator + ConstantSign.DOWNAPP;
            FileUtils.createOrExistsDir(imagePathFolder);
            //FileUtils.createOrExistsFile(imagePathFolder);
            String imagePathFile = PathUtils.getExternalAppFilesPath() + File.separator + ConstantSign.DOWNAPP + File.separator + ConstantSign.IMG + TimeUtils.getNowString() + ConstantSign.IMG_POSTFIX;
            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "图片的本地路径是-->" + imagePathFile);
            //itchen-->图片的本地路径是-->/storage/emulated/0/Android/data/com.ygxsk.carhome/files/downapp/img2023-10-26 19:50:26.jpg
//            String testUrl = "http://222.222.17.184:8990/resource/image/houseTypeImg/20230818/2023081809380999347987.png";
            method_inside_download(_imageUrl, imagePathFile);

            //将图片下载到指定目录:
//            boolean resultValue = DemoImage.base64ToImage(_imageUrlBase64, imagePath);
//            //boolean resultValue = DemoImage.base64ToImage(_imageUrlBase64, PathUtils.getExternalAppFilesPath() + File.separator + ConstantSign.IMG + TimeUtils.getNowString() + ConstantSign.IMG_POSTFIX);

            Glide.with(InputCustomerActivity.this)
                    .load(_imageUrl)
                    .placeholder(R.drawable.icon_errorfang)//
                    .error(R.drawable.icon_errorfang)//
                    .fitCenter()
                    .diskCacheStrategy(DiskCacheStrategy.NONE)//动态获取新值不缓存
//                        .override(120, 60)
                    .into(imageViewQRCode);

//                点击查看大图
            if (imageViewQRCode != null) {
                imageViewQRCode.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
                    @Override
                    public void onDebouncingClick(View v) {
                        //验证码的查看大图
                        new XPopup.Builder(InputCustomerActivity.this)
                                .asImageViewer(imageViewQRCode, //
                                        _imageUrl,//直接展示动态链接图，或者静态图也可以
                                        new SmartGlideImageLoader())//
                                .show();
                    }
                });
            }

            //客户二维码关闭的话，也要刷新列表
            if (textViewCardCancel != null) {
                textViewCardCancel.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
                    @Override
                    public void onDebouncingClick(View v) {

                        //此时 弹窗是已经被弹出的
                        if (materialDialogCustomView != null) {
                            materialDialogCustomView.dismiss();
                        }

                        //客户认证完毕，应该是新建了一个档案盒子；要刷新
                        EventSignatureMain eventSignatureMainList = new EventSignatureMain();
                        eventSignatureMainList.setMessage(ExtraValue.EVENTBUS_EVENT_TO_REFRESH_SIGNATURE_MAIN_LIST);
                        EventBus.getDefault().post(eventSignatureMainList);

                    }
                });
            }

            //点击打开图片的时候就关闭弹窗：
            if (textViewCardSure != null) {

                textViewCardSure.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
                    @Override
                    public void onDebouncingClick(View v) {

                        //该页面有查看图片的权限
                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {

                            //获取权限
                            if (!AndPermission.hasPermissions(mActivityInstance, Permission.WRITE_EXTERNAL_STORAGE)
                                    || !AndPermission.hasPermissions(mActivityInstance, Permission.READ_EXTERNAL_STORAGE)) {

                                CommUtils.checkMaterialDialog(materialDialog);

                                materialDialog = CommUtils.authorityRequest(mActivityInstance, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_STORAGE, new AuthorityCallbackListener() {
                                    @Override
                                    public void doSomeThing() {

                                        CommUtils.checkMaterialDialog(materialDialog);

                                        //添加访问权限内容
                                        AndPermission.with(InputCustomerActivity.this)
                                                .runtime()//
                                                .permission(Permission.READ_EXTERNAL_STORAGE, //
                                                        Permission.WRITE_EXTERNAL_STORAGE)//
                                                .rationale(new RuntimeRationale())//
                                                .onGranted(new com.yanzhenjie.permission.Action<List<String>>() {
                                                    @Override
                                                    public void onAction(List<String> permissions) {

                                                        if (materialDialogCustomView != null) {
                                                            materialDialogCustomView.dismiss();
                                                        }


                                                        methodOpenImage(imagePathFolder);

                                                    }
                                                }).onDenied(new com.yanzhenjie.permission.Action<List<String>>() {
                                                    @Override
                                                    public void onAction(List<String> permissions) {

                                                        ToastUtils.showShort(ConstantSign.NEEDPERMISS_PHONE);

                                                        PermissionSetting permissionSetting = new PermissionSetting(mActivityInstance);

                                                        if (AndPermission.hasAlwaysDeniedPermission(InputCustomerActivity.this, permissions)) {
                                                            permissionSetting.showSetting(ConstantApi.PERMISSION_NORMAL, InputCustomerActivity.this, permissions);
                                                        }

                                                    }
                                                }).start();

                                    }
                                });

                            } else {

                                if (materialDialogCustomView != null) {
                                    materialDialogCustomView.dismiss();
                                }

                                methodOpenImage(imagePathFolder);

                            }

                        } else {

                            if (!XXPermissions.isGranted(InputCustomerActivity.this, com.hjq.permissions.Permission.READ_MEDIA_IMAGES)) {

                                CommUtils.checkMaterialDialog(materialDialog);

                                materialDialog = CommUtils.authorityRequest(mActivityInstance, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_ALBUM, new AuthorityCallbackListener() {

                                    @Override
                                    public void doSomeThing() {

                                        CommUtils.checkMaterialDialog(materialDialog);

                                        XXPermissions.with(InputCustomerActivity.this)
                                                // 适配分区存储应该这样写
                                                //.permission(Permission.Group.STORAGE)
                                                // 不适配分区存储应该这样写
//                                             .permission(com.hjq.permissions.Permission.)//
                                                .permission(com.hjq.permissions.Permission.READ_MEDIA_IMAGES)//
                                                .interceptor(new PermissionInterceptor())
                                                .request(new OnPermissionCallback() {

                                                    @Override
                                                    public void onGranted(@NonNull List<String> permissions, boolean allGranted) {

                                                        if (!allGranted) {
                                                            return;
                                                        }

                                                        Toaster.show(String.format(getString(R.string.demo_obtain_permission_success_hint),
                                                                PermissionNameConvert.getPermissionString(InputCustomerActivity.this, permissions)));

                                                        if (materialDialogCustomView != null) {
                                                            materialDialogCustomView.dismiss();
                                                        }

                                                        methodOpenImage(imagePathFolder);

                                                    }
                                                });

                                    }
                                });

                            } else {
                                if (materialDialogCustomView != null) {
                                    materialDialogCustomView.dismiss();
                                }

                                methodOpenImage(imagePathFolder);
                            }

                        }
                    }
                });
            }

            //激发 弹窗弹出内容
            materialDialogCustomView = new MaterialDialog.Builder(InputCustomerActivity.this)
                    .customView(viewCard, false)
                    .contentColor(ColorUtils.getColor(R.color.buttonnomcolor))//
                    //.positiveText("确定")
                    .positiveColor(ColorUtils.getColor(R.color.dark))
                    //.negativeText("取消")
                    .canceledOnTouchOutside(false)
                    .show();

            //materialDialog.getTitleView().setTextSize(16f);

        }

    }

    //请求发现用户已经完成法大大认证，那么直接弹窗，让用户新建合同，跳转到新建合同页面，发起签约
    //直接新建一个合同 也会新建一个盒子？
    private void method_show_QRCode_dialog_customer_has_signature(SignatureWebInformationBean _signatureWebInformationBean) {

        View viewCard = View.inflate(mActivityInstance, R.layout.qrcodemiddlepopuhassignature, null);

        if (viewCard != null) {

            //关闭 按钮
            RoundTextView textViewCardCancel = (RoundTextView) viewCard.findViewById(R.id.textviewqrcodecancel_createagr);
            //保存为图片的按钮
            RoundTextView textViewCardSure = (RoundTextView) viewCard.findViewById(R.id.textviewqrcodesave_createagr);

            //关闭弹窗，就不用新建合同，或者去查找这个用户的档案盒子；
            if (textViewCardCancel != null) {
                textViewCardCancel.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
                    @Override
                    public void onDebouncingClick(View v) {

                        //此时 弹窗是已经被弹出的
                        if (materialDialogCustomView != null) {
                            materialDialogCustomView.dismiss();
                        }

                    }
                });
            }

            //打开跳转到 新建合同页面
            if (textViewCardSure != null) {

                textViewCardSure.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
                    @Override
                    public void onDebouncingClick(View v) {

                        if (materialDialogCustomView != null) {
                            materialDialogCustomView.dismiss();
                        }

                        //携带informationid过去 要做记录的，从哪儿跳转的，因为直接新建一个合同
//                        {
//                            "code":"20000",
//                                "data":{
//                                    "authUrl":"https://80000333.uat-e.fadada.com/authorizeui/person/login?authSerial=268ffe819c49428e8bc517f76e4dc5db",
//                                    "qrUrl":"http://222.222.17.184:8990/resource/file/information/fasc/qr/18810042041-1499认证二维码.jpg",
//                                    "fascAuth":false,
//                                    "informationId":22
//                                    },
//                            "message":"success"
//                        }

                        //以这里做提交入口
                        Bundle extra_bundle = new Bundle();
                        //携带这条信息过去，有一些初始化值，到下一个界面；
                        extra_bundle.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, ExtraValue.VALUE_JUMP_FORM_SIGNATRUE_ACTIVITY);
                        //单个合同，是空的；
                        extra_bundle.putParcelable(ExtraKey.EXTRA_SIGNATURE_FILESIGNATURE_AGREEMENT, null);

                        //单个档案盒子
                        FileSignatureManage fileSignatureManage_extra = new FileSignatureManage();
                        //用户提交时候返回来的档案盒子id;
                        fileSignatureManage_extra.setInformationId(_signatureWebInformationBean.getInformationId());
                        //用户在提交的时候选中的类型id
                        fileSignatureManage_extra.setVehicleType(archiveTypeId_upLoad);

                        extra_bundle.putParcelable(ExtraKey.EXTRA_SIGNATURE_FILESIGNATUREMANAGE, fileSignatureManage_extra);

                        ActivityUtils.startActivity(extra_bundle, SignatureAddSubmitToActivity.class);

                        // TODO: 2023-11-27 10:32 界面要关闭，不然填完合同还在该界面
                        methodBack();

                    }
                });
            }

            //激发 弹窗弹出内容
            materialDialogCustomView = new MaterialDialog.Builder(InputCustomerActivity.this)
                    .customView(viewCard, false)
                    .contentColor(ColorUtils.getColor(R.color.buttonnomcolor))//
                    //.positiveText("确定")
                    .positiveColor(ColorUtils.getColor(R.color.dark))
                    //.negativeText("取消")
                    .canceledOnTouchOutside(false)
                    .show();

            //materialDialog.getTitleView().setTextSize(16f);

        }

    }

    private void gain_send_signature_links_to_customer() {

        clientPhone_upLoad = editViewPhoneEvaluate.getText().toString().trim();
        clientName_upLoad = editViewCustomerName.getText().toString().trim();
        idCard_upLoad = editViewIdCard.getText().toString().trim();

        if (NetworkUtils.isConnected()) {

            HashMap<String, Object> map = new HashMap<>();
            map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());//,
            map.put(Parameterkey.clientPhone, clientPhone_upLoad);//,客户手机号

            //让填写，但是接口上不上传。
            map.put(Parameterkey.clientName, clientName_upLoad);//客户姓名
            map.put(Parameterkey.idCard, idCard_upLoad);//客户身份证号码

            map.put(Parameterkey.clientType, clientType_upLoad);//,clientType 客户类型(0:个人;1:企业),默认是个人
            map.put(Parameterkey.archiveTypeId, archiveTypeId_upLoad);//档案的类型，是新车 还是二手车

            AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
            addLogUpLoadInfo.setActivity(mActivityInstance);
            addLogUpLoadInfo.setWhat(ConstantApi.WHAT_SENDOPENFASCAUTHURL_URL);//请求数字标识
            addLogUpLoadInfo.setUrlPath(ApiService.sendOpenFascAuthUrl_url);//url地址
            addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
            addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
            addLogUpLoadInfo.setHashMapParameter(map);

            NetworkManager.getInstance().initRetrofitRxJava()
                    .create(ApiService.class)
                    .sendOpenFascAuthUrl(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                            MediaType.parse(ApiService.HEADER_JSON)))
                    .compose(InputCustomerActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                    .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<SignatureWebInformationBean>() {
                        @Override
                        public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                            super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                            //{"data":"","message":"无更多数据","code":"29999"}
                            CommUtils.checkMaterialDialog(materialDialog);

                            //这里要不要给提示？无更多数据
                            if (!TextUtils.isEmpty(serverMessage)) {
                                ToastUtils.showShort(serverMessage);
                            }

                        }
                    })).doOnSubscribe(new Consumer<Disposable>() {
                        @Override
                        public void accept(Disposable disposable) throws Throwable {
                            //
                            method_create_materialDialog(mActivityInstance, ConstantSign.TIPS_SUBMIT);
                        }
                    }).subscribe(new Consumer<SignatureWebInformationBean>() {
                        @Override
                        public void accept(SignatureWebInformationBean signatureWebInformationBean) throws Throwable {


//                            {
//                                "code":"20000",
//                                    "data":{
//                                     "authUrl":"https://80000333.uat-e.fadada.com/authorizeui/person/login?authSerial=839075a5cb244d4baefcad8051f137dd",
//                                        "fascAuth":false,
//                                        "informationId":45
//                            },
//                                "message":"success"
//                            }

                            CommUtils.checkMaterialDialog(materialDialog);

                            // TODO: 2023-10-26 18:25 存入本地 做接口携带用到；
                            //存入 informationId 的值内容；
                            String informationId = signatureWebInformationBean.getInformationId();
                            mSession.setInformationId(informationId);

                            //MMKV.defaultMMKV().encode(ConstantSign.P_INFORMATIONID, informationId);
                            String authUrl = signatureWebInformationBean.getAuthUrl();

                            //获取这个客户是否已经开通过法大大
                            boolean fascAuth = signatureWebInformationBean.getFascAuth();

                            if (fascAuth) {

                                //如果用户已经开通过法大大，那么，提示，并跳转到档案盒子，添加
                                PopTip.show(getResources().getString(R.string.send_links_to_hasqrcode)).iconSuccess();

                                //客户已经认证过法大大认证，请新建合同；
                                method_show_QRCode_dialog_customer_has_signature(signatureWebInformationBean);

                            } else {

                                //2023-11-27 10:07:01--发送认证链接是空值，也提示？
                                if (!TextUtils.isEmpty(authUrl)) {

                                    //提示发送成功或者失败：
                                    PopTip.show(getResources().getString(R.string.send_links_to_customer)).iconSuccess();

                                    //直接打开客户认证的链接
                                    ViewUitls.method_toWebView_signature(getString(R.string.title_dialog_signature_customer), authUrl);

                                }

                            }

                        }
                    }, new ErrorConsumer() {

                        @Override
                        protected void error(ApiException apiException) {

                            CommUtils.checkMaterialDialog(materialDialog);

                            //页面报错；给提示
                            if (apiException != null) {
                                ToastUtils.showShort(apiException.getDisplayMessage());
                            }

                        }
                    });

        } else {

            ToastUtils.showShort(StringUtils.getString(R.string.http_exception_network));

        }


    }

    //直接打开文件的路径，打开文件,2023-10-27 09:04:42 我指定的是打开文件夹：
    private void methodOpenImage(String _imagePathFolder) {

        //直接打开到文件夹
        final ZFileConfiguration configuration = new ZFileConfiguration.Build()
                .filePath(PathUtils.getExternalAppFilesPath() + File.separator + ConstantSign.DOWNAPP + File.separator)
                .boxStyle(ZFileConfiguration.STYLE2)
//                .sortordBy(ZFileConfiguration.BY_DEFAULT)
                .sortordBy(ZFileConfiguration.BY_DATE)//按照日期的顺序排序
                .sortord(ZFileConfiguration.DESC)//倒序排列
                .maxLength(1)
                .maxLengthStr("最多选1个！")
                .useSAF(false)
                .build();

        ZFileContent.getZFileHelp()
                .setConfiguration(configuration)
                .start(InputCustomerActivity.this);

    }

    //直接执行下载
    private void method_inside_download(String _downLoadUrlCurrent, String _imagePathLocal) {

        //使用第三方下载
        taskDownLoadApkId = Aria.download(this)
                .load(_downLoadUrlCurrent)
                .setFilePath(_imagePathLocal) //设置文件保存的完整路径,我设置的全路径
                .create();   //启动下载

    }

    //在这里处理任务执行中的状态，如进度进度条的刷新
    @Download.onTaskRunning
    protected void running(DownloadTask task) {

//        if(task.getKey().eques(task.getKey())){
//        ....
//            可以通过url判断是否是指定任务的回调
//        }
        int p = task.getPercent();  //任务进度百分比
//        String speed = task.getConvertSpeed();  //转换单位后的下载速度，单位转换需要在配置文件中打开
//        String speed1 = String.valueOf(task.getSpeed()); //原始byte长度速度
//        LogUtils.d(ConstantSign.LOGCAT_NOMAL+"下载进度是-->"+speed);
        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "下载进度是-->" + p);

//        if (callbackResult != null) {
//            callbackResult.OnBackResult(p);
//        }

    }

    @Download.onTaskComplete
    void taskComplete(DownloadTask task) {
        //在这里处理任务完成的状态
        //下载完毕
        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "下载完毕；");
        //String filePath = PathUtils.getExternalAppCachePath() + File.separator + (_downLoadUrlCurrent.substring(_downLoadUrlCurrent.lastIndexOf("/") + 1));
        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "下载完毕后的地址-->" + task.getFilePath());
        //itchen-->下载完毕后的地址-->/storage/emulated/0/Android/data/com.ygxsk.carhome/files/downapp/img2023-10-27 08:54:36.jpg

        //直接启用安装
//        if (!TextUtils.isEmpty(task.getFilePath())) {
//            if (CommUtils.getUninatllApkInfo(LoginCarActivity.this, task.getFilePath())) {
//                ///data/user/0/com.ygxsk.integrated/cache/2970b8290303428eb08f0805be10db3d.apk
//                AppUtils.installApp(task.getFilePath());
//            }
//        }

    }

    @Download.onTaskCancel
    void taskCancel(DownloadTask task) {

        //LogUtils.d(ConstantSign.LOGCAT_NOMAL+"---->下载取消---");

        //mAdapter.updateState(task.getEntity());
        //判断这个任务在运行的状态中，那么，就直接停止它；
//        if (Aria.download(SettingActivity.this).load(taskDownLoadApkId).isRunning()){
//            Aria.download(SettingActivity.this).load(taskDownLoadApkId).stop();
//        }

        //直接关闭 下载弹窗；
        //立即关闭弹窗的
//        CommUtils.checkMaterialDialog(materialDialogHasUpdateData);
//        CommUtils.checkMaterialDialog(materialDialogDownLoadProgress);

        ToastUtils.showLong(R.string.downlaodappcancel);

    }

    /**
     * @param e 异常信息
     */
    @Download.onTaskFail
    void taskFail(DownloadTask task, Exception e) {

        //立即关闭弹窗的
//        CommUtils.checkMaterialDialog(materialDialogHasUpdateData);
//        CommUtils.checkMaterialDialog(materialDialogDownLoadProgress);

        //ALog.d(TAG, ALog.getExceptionString(e));
        //下载任务失败
        //下载失败
        if (!TextUtils.isEmpty(ALog.getExceptionString(e))) {

            ToastUtils.showShort(ALog.getExceptionString(e));
//            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "---->下载报错--->" + ALog.getExceptionString(e));
            //提示下载失败：
            ToastUtils.showShort(ALog.getExceptionString(e));

        }

    }

    @Override
    protected void gainDatas() {

        //

    }

    //相机拍照
    private void methodPicCallBackCamera() {

        //添加拍照
        Album.camera(InputCustomerActivity.this)//
                .image()//
                .filePath(PathUtils.getExternalAppFilesPath() + File.separator + ConstantSign.STARTWITH_UCROP_FLAG + TimeUtilSer.getNowPic() + ".jpg")
                .onResult(new Action<String>() {
                    @Override
                    public void onAction(@NonNull String result) {

                        //拍照路径内容

                        //裁剪执行
                        takePicture(result);


                    }

                }).onCancel(new Action<String>() {
                    @Override
                    public void onAction(@NonNull String result) {
                        ToastUtils.showShort(StringUtils.getString(R.string.cancelinfo));
                    }

                }).start();


    }

    /**
     * @date 2018/1/31 0031
     * @auther itchenqi
     * @description 对图片做剪裁内容
     */
    private void takePicture(String pathString) {

        //填充
//        UCrop uCrop = UCrop.of(Uri.fromFile(new File(pathString)), Uri.fromFile(new File(getCacheDir(), "SampleCropImage")));
//        UCrop uCrop = UCrop.of(Uri.fromFile(new File(pathString)), Uri.fromFile(new File(PathUtils.getExternalAppFilesPath(), "SampleCropImage")));
        UCrop uCrop = UCrop.of(Uri.fromFile(new File(pathString)), Uri.fromFile(new File(PathUtils.getExternalAppFilesPath() + File.separator + TimeUtilSer.getNowPic() + ".jpg")));

//        uCrop = basisConfig(uCrop);
        uCrop = advancedConfig(uCrop);

        uCrop.start(InputCustomerActivity.this);

    }

    /**
     * Sometimes you want to adjust more options, it's done via {@link com.yalantis.ucrop.UCrop.Options} class.
     *
     * @param uCrop - ucrop builder instance
     * @return - ucrop builder instance
     */
    private UCrop advancedConfig(@NonNull UCrop uCrop) {

        UCrop.Options options = new UCrop.Options();

//        switch (mRadioGroupCompressionSettings.getCheckedRadioButtonId()) {
//            case R.id.radio_png:
//                options.setCompressionFormat(Bitmap.CompressFormat.PNG);
//                break;
//            case R.id.radio_jpeg:
//            default:
//                options.setCompressionFormat(Bitmap.CompressFormat.JPEG);
//                break;
//        }

        options.setCompressionFormat(Bitmap.CompressFormat.PNG);

//        options.setCompressionQuality(mSeekBarQuality.getProgress());

//        options.setHideBottomControls(mCheckBoxHideBottomControls.isChecked());
//        options.setFreeStyleCropEnabled(mCheckBoxFreeStyleCrop.isChecked());

        /*
        If you want to configure how gestures work for all UCropActivity tabs

        options.setAllowedGestures(UCropActivity.SCALE, UCropActivity.ROTATE, UCropActivity.ALL);
        * */

        /*
        This sets max size for bitmap that will be decoded from source Uri.
        More size - more memory allocation, default implementation uses screen diagonal.

        options.setMaxBitmapSize(640);
        * */


       /*

        Tune everything (ﾉ◕ヮ◕)ﾉ*:･ﾟ✧

        options.setMaxScaleMultiplier(5);
        options.setImageToCropBoundsAnimDuration(666);
        options.setDimmedLayerColor(Color.CYAN);
        options.setCircleDimmedLayer(true);
        options.setShowCropFrame(false);
        options.setCropGridStrokeWidth(20);
        options.setCropGridColor(Color.GREEN);
        options.setCropGridColumnCount(2);
        options.setCropGridRowCount(1);
        options.setToolbarCropDrawable(R.drawable.your_crop_icon);
        options.setToolbarCancelDrawable(R.drawable.your_cancel_icon);

        // Color palette
        options.setToolbarColor(ContextCompat.getColor(this, R.color.your_color_res));
        options.setStatusBarColor(ContextCompat.getColor(this, R.color.your_color_res));
        options.setToolbarWidgetColor(ContextCompat.getColor(this, R.color.your_color_res));
        options.setRootViewBackgroundColor(ContextCompat.getColor(this, R.color.your_color_res));
        options.setActiveControlsWidgetColor(ContextCompat.getColor(this, R.color.your_color_res));

        // Aspect ratio options
        options.setAspectRatioOptions(2,
            new AspectRatio("WOW", 1, 2),
            new AspectRatio("MUCH", 3, 4),
            new AspectRatio("RATIO", CropImageView.DEFAULT_ASPECT_RATIO, CropImageView.DEFAULT_ASPECT_RATIO),
            new AspectRatio("SO", 16, 9),
            new AspectRatio("ASPECT", 1, 1));
        options.withAspectRatio(CropImageView.DEFAULT_ASPECT_RATIO, CropImageView.DEFAULT_ASPECT_RATIO);
        options.useSourceImageAspectRatio();

       */

        return uCrop.withOptions(options);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
            //&& requestCode == UCrop.REQUEST_CROP
            final Uri resultUri = UCrop.getOutput(data);

            if (resultUri != null && resultUri.getScheme().equals("file")) {

//            if (resultUri != null) {

                try {
//                    copyFileToDownloads(getIntent().getData());
                    String imagePath = resultUri.getPath();

                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "imagePath-->" + imagePath);
//                    itchen-->imagePath-->/storage/emulated/0/Android/data/com.ygxsk.carhome/files/2023_11_23_14_09_51_360.jpg
                    //itchen-->imagePath-->/storage/emulated/0/Android/data/com.ygxsk.carhome/files/2023_11_23_14_14_09_679.jpg
                    //itchen-->imagePath-->/storage/emulated/0/Android/data/com.ygxsk.carhome/files/2023_11_23_19_16_16_693.jpg
                    //itchen-->imagePath-->/storage/emulated/0/Android/data/com.ygxsk.carhome/files/2023_11_23_19_16_16_693.jpg

                    //上传图片内容？
                    //展示图片
                    method_handler_idCardImage(imagePath);

                } catch (Exception e) {

//                    Toast.makeText(ResultActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                    if (e != null) {
                        LogUtils.d(ConstantSign.LOGCAT_NOMAL, e.getLocalizedMessage());
                    }

                }

            } else {
//                Toast.makeText(ResultActivity.this, getString(R.string.toast_unexpected_error), Toast.LENGTH_SHORT).show();
                ToastUtils.showShort("执行异常~");
                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "imagePath-->" + "执行异常");
            }

        } else if (resultCode == UCrop.RESULT_ERROR) {

            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "cropError-->" + "cropError");
            final Throwable cropError = UCrop.getError(data);

            if (cropError != null) {
                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "cropError.getLocalizedMessage-->" + cropError.getLocalizedMessage());
            }

        } else if (resultCode == IDCardCamera.RESULT_CODE) {

            //获取图片路径，显示图片
            final String imagePath = IDCardCamera.getImagePath(data);

            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--imagePath-->" + imagePath);
            //日志不能删除，为了查看拍照裁剪之后的路径
            //itchen-->--imagePath-->/storage/emulated/0/WildmaIDCardCamera/WildmaIDCardCamera.idCardFrontCrop.jpg

            if (!TextUtils.isEmpty(imagePath)) {

                if (requestCode == IDCardCamera.TYPE_IDCARD_FRONT) { //身份证正面

//                    mIvFront.setImageBitmap(BitmapFactory.decodeFile(path));

                    //长按是查看大图,这时候路径不是空，那么设置点击查看大图
                    method_handler_idCardImage(imagePath);


                } else if (requestCode == IDCardCamera.TYPE_IDCARD_BACK) {  //身份证反面

//                    mIvBack.setImageBitmap(BitmapFactory.decodeFile(path));

                }
            }

        } else if (resultCode == RESULT_OK && requestCode == RC_CHOOSE_PHOTO) {

            //添加图片内容，是从相册选择的
            ArrayList<String> list = BGAPhotoPickerPreviewActivity.getSelectedPhotos(data);

            if (list != null) {

                String imagePath = list.get(0);

                //选中的图片路径是：
                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "从相册选中的图片路径是-->" + imagePath);
                //itchen-->从相册选中的图片路径是-->/storage/emulated/0/temp/1700647204675.jpg
                if (!TextUtils.isEmpty(imagePath)) {
                    takePicture(imagePath);
                } else {
                    ToastUtils.showShort(getResources().getString(R.string.action_abnormal));
                }

                //如下是直接上传的逻辑，但是需要裁剪的
//                if (imageViewIdCardInfo != null) {
//
//                    imageViewIdCardInfo.setOnLongClickListener(new View.OnLongClickListener() {
//                        @Override
//                        public boolean onLongClick(View v) {
//
//                            //验证码的查看大图
//                            new XPopup.Builder(InputCustomerActivity.this)
//                                    .asImageViewer(imageViewIdCardInfo, //
//                                            imagePath,//
//                                            new SmartGlideImageLoader())//
//                                    .show();
//
//                            return true;
//                        }
//                    });
//
//                }
//
//                method_show_image_result(imagePath);
//
//                method_upLoad_idCard(imagePath);

            }

        }

    }

    private void method_handler_idCardImage(String imagePath) {
        if (imageViewIdCardInfo != null) {
            imageViewIdCardInfo.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {

                    //验证码的查看大图
                    new XPopup.Builder(InputCustomerActivity.this)
                            .asImageViewer(imageViewIdCardInfo, //
                                    imagePath,//
                                    new SmartGlideImageLoader())//
                            .show();

                    return true;
                }
            });
        }

        method_show_image_result(imagePath);
        method_upLoad_idCard(imagePath);
    }

    private void method_show_image_result(String imagePath) {

        Glide.with(InputCustomerActivity.this)
                .load(imagePath)
                .skipMemoryCache(true)//跳过内存缓存
                .diskCacheStrategy(DiskCacheStrategy.NONE)//不在磁盘中缓存
                .placeholder(R.drawable.defaulttoub)//
                .error(R.drawable.defaulttoub)//
                .fallback(R.drawable.defaulttoub)//
//                .centerCrop()
                //.transition(withCrossFade())
                .into(new CustomTarget<Drawable>() {
                    @Override
                    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                        //手动指定图片内容
                        if (imageViewIdCardInfo != null) {
                            imageViewIdCardInfo.setImageDrawable(resource);
                        }
                    }

                    @Override
                    public void onLoadCleared(@Nullable Drawable placeholder) {

                        //加载失败 ？

                    }
                });


    }


    //这种是使用正常的接口调用API写的
//    {
//        "id_card": "411521199001301532",
//         "name": "陈奇"
//    }

    //使用单独的方式改造：
    private void method_upLoad_idCard(String _filePathLocal) {

        //配置okHttp的参数
//        OkHttpClient okHttpClient = new OkHttpClient.Builder()
//                .connectTimeout(3000, TimeUnit.SECONDS)
//                .build();

//        获取Retrofit对象
//        mRetrofit = new Retrofit.Builder()
//                .baseUrl(ApiService.idcardupload_url)//设置BaseUrl 必须以'/'结尾
//                .client(okHttpClient)//设置使用OkHttp请求
//                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())//配置回调库，采用RxJava
//                .build()

        Retrofit mRetrofit = NetworkManager.getInstance().initRetrofitRxJava();
        GoogleService googleService = mRetrofit.create(GoogleService.class);
        MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder()//
                .setType(MultipartBody.FORM);//
        File filUpLoad = new File(_filePathLocal);

        if (filUpLoad != null) {
            //是单个的文件，只需要添加一个即可
            multipartBodyBuilder.addFormDataPart(Parameterkey.file, filUpLoad.getName(),//
                    RequestBody.create(filUpLoad, MediaType.parse(ApiService.MEDIATYPE_IMAGE_JPG)));//
        }

        Observable<String> observable = googleService.idcardUpLoad(multipartBodyBuilder.build());

        observable
                .compose(InputCustomerActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .subscribeOn(Schedulers.io())//这种方式也可以
//                .subscribeOn(AndroidSchedulers.mainThread())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

                        //查看一下 是什么线程？
                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "doOnSubscribe--doOnSubscribe--doOnSubscribe");
//                        main, com.ygxsk.carhome.ui.signature.InputCustomerActivity$27.accept(InputCustomerActivity.java:1919)
//                        itchen-->doOnSubscribe--doOnSubscribe--doOnSubscribe

//                        CommUtils.checkMaterialDialog(materialDialog);
//                        if (materialDialog == null) {
                        method_create_materialDialog(mActivityInstance, ConstantSign.TIPS_SUBMIT);
//                        }

                    }
                })
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(@io.reactivex.rxjava3.annotations.NonNull Disposable d) {
                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "onSubscribe--onSubscribe--onSubscribe");
//                        main, com.ygxsk.carhome.ui.signature.InputCustomerActivity$26.onSubscribe(InputCustomerActivity.java:1931)
//                        itchen-->onSubscribe--onSubscribe--onSubscribe
                    }

                    @Override
                    public void onNext(@io.reactivex.rxjava3.annotations.NonNull String s) {

                        CommUtils.checkMaterialDialog(materialDialog);

                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "查看解析的内容是-->" + s);
                        //主要的查看所在线程的打印信息：
//                        main, com.ygxsk.carhome.ui.signature.InputCustomerActivity$26.onNext(InputCustomerActivity.java:1923)
//                        itchen-->查看解析的内容是-->{"id_card":"310230198804123726","name":"陆龚联"}

                        //转换内容
                        IdCardInfo idCardInfo = JSON.parseObject(s, IdCardInfo.class);

                        if (idCardInfo != null) {

                            if (idCardInfo != null) {

                                //姓名内容
                                String name = idCardInfo.getName();

                                //身份证内容
                                String id_card = idCardInfo.getIdCard();

                                if (!TextUtils.isEmpty(name)) {

                                    //填充客户姓名
                                    Delivery.getInstance().post(new Runnable() {
                                        @Override
                                        public void run() {

                                            if (editViewCustomerName != null) {
                                                editViewCustomerName.setText(name);
                                            }

                                        }
                                    });

                                }

                                //填充客户身份证号
                                if (!TextUtils.isEmpty(id_card)) {

                                    Delivery.getInstance().post(new Runnable() {
                                        @Override
                                        public void run() {

                                            if (editViewIdCard != null) {
                                                editViewIdCard.setText(id_card);
                                            }

                                        }
                                    });
                                }

                            } else {

                                //如果是识别不出，给个提示
                                ToastUtils.showShort(getResources().getString(R.string.idcard_know_abnomal));

                            }

                        }

                    }

                    @Override
                    public void onError(@io.reactivex.rxjava3.annotations.NonNull Throwable apiException) {

                        //处理报错信息
                        CommUtils.checkMaterialDialog(materialDialog);

                        //图片上传失败；给提示
                        if (apiException != null) {
                            ToastUtils.showShort(apiException.getMessage());
                        }

                    }

                    @Override
                    public void onComplete() {
                        //上传完毕
                        CommUtils.checkMaterialDialog(materialDialog);
                    }
                });

//        observable
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Consumer<String>() {
//                    @Override
//                    public void accept(String s) throws Throwable {
//
//                    }
//                });

    }


    //单独上传身份证图片内容；
//    private void method_upLoad_idCard(String _filePathLocal) {
//
//        HashMap<String, Object> map = new HashMap<>();
//        map.put(Parameterkey.file, _filePathLocal);//
//
//        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
//        addLogUpLoadInfo.setActivity(mActivityInstance);
//        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_UPLOADACCESSORY_URL);//请求数字标识
//        addLogUpLoadInfo.setUrlPath(ApiService.uploadAccessory_url);//url地址
//        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
//        addLogUpLoadInfo.setToastToUser(false);//展示给用户的标志
//        addLogUpLoadInfo.setHashMapParameter(map);
//
//        //上传的是文件：
//        MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder()//
//                .setType(MultipartBody.FORM);//
//
//        File filUpLoad = new File(_filePathLocal);
//
//        if (filUpLoad != null) {
//            //是单个的文件，只需要添加一个即可
//            multipartBodyBuilder.addFormDataPart(Parameterkey.file, filUpLoad.getName(),//
//                    RequestBody.create(filUpLoad, MediaType.parse(ApiService.MEDIATYPE_IMAGE_JPG)));//
//        }
//
//        NetworkManager.getInstance().initRetrofitRxJava()
//                .create(ApiService.class)
//                //.uploadSingle(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue), MediaType.parse(ApiService.HEADER_JSON)))
//                .idcardUpLoad(multipartBodyBuilder.build())
//                .compose(InputCustomerActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
//                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<IdCardInfo>() {
//                    @Override
//                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
//                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);
//
//                        CommUtils.checkMaterialDialog(materialDialog);
//
//                        //如果上传报错，提示报错信息
//                        if (!TextUtils.isEmpty(serverMessage)) {
//                            ToastUtils.showShort(serverMessage);
//                        }
//
//                    }
//                })).doOnSubscribe(new Consumer<Disposable>() {
//                    @Override
//                    public void accept(Disposable disposable) throws Throwable {
////                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "添加上传图片的接口---响应的-->" + _filePathLocal);
//                        CommUtils.checkMaterialDialog(materialDialog);
//
//                        if (materialDialog == null) {
//                            method_create_materialDialog(ConstantSign.TIPS_SUBMIT);
//                        }
//
//                    }
//                }).subscribe(new Consumer<IdCardInfo>() {
//                    @Override
//                    public void accept(IdCardInfo idCardInfo) throws Throwable {
//
////                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "添加上传图片的接口--响应的数据-->" + fileSingleUpLoadBean.getFileName());
//
//                        if (idCardInfo != null) {
//
//                            //姓名内容
//                            String name = idCardInfo.getName();
//
//                            //身份证内容
//                            String id_card = idCardInfo.getIdCard();
//
//                            if (!TextUtils.isEmpty(name)) {
//
//
//                                //填充客户姓名
//                                Delivery.getInstance().post(new Runnable() {
//                                    @Override
//                                    public void run() {
//
//                                        if (editViewCustomerName != null) {
//                                            editViewCustomerName.setText(name);
//                                        }
//
//                                    }
//                                });
//
//                            }
//
//                            //填充客户身份证号
//                            if (!TextUtils.isEmpty(id_card)) {
//
//                                Delivery.getInstance().post(new Runnable() {
//                                    @Override
//                                    public void run() {
//
//                                        if (editViewIdCard != null) {
//                                            editViewIdCard.setText(id_card);
//                                        }
//
//                                    }
//                                });
//                            }
//
//                        } else {
//
//                            //如果是识别不出，给个提示
//                            ToastUtils.showShort(getResources().getString(R.string.idcard_know_abnomal));
//
//                        }
//
//                    }
//                }, new ErrorConsumer() {
//
//                    @Override
//                    protected void error(ApiException apiException) {
//
//                        CommUtils.checkMaterialDialog(materialDialog);
//
//                        //图片上传失败；给提示
//                        if (apiException != null) {
//                            ToastUtils.showShort(apiException.getDisplayMessage());
//                        }
//
//                    }
//
//                });
//
//    }

    @Override
    protected void methodBack() {

        methodBackFinish();

    }

    @Override
    public void processExtraData() {

        Bundle extras_bundle = this.getIntent().getExtras();

        if (extras_bundle != null) {

            //标志 是 添加 潜客 或者 是修改潜客 信息
            flag_jumpfrom_where = extras_bundle.getInt(ExtraKey.EXTRA_JUMPFROM_WHERE);

            extra_signature_fileSignatureManage = extras_bundle.getParcelable(ExtraKey.EXTRA_SIGNATURE_FILESIGNATUREMANAGE);

            //如果是【编辑】过来的，将携带的数据赋值，并且填充textview或者editview
//            if (extra_signature_fileSignatureAgreement != null) {
//                vehicleType_upLoad = extra_signature_fileSignatureManage.getVehicleType();
//                informationId_upLoad = extra_signature_fileSignatureAgreement.getInformationId();
//                LogUtils.json(ConstantSign.LOGCAT_NOMAL + "这是详情携带的数据--extra_signature_fileSignatureAgreement", extra_signature_fileSignatureAgreement);
//                LogUtils.json(ConstantSign.LOGCAT_NOMAL + "这是详情携带的数据--informationId_upLoad", informationId_upLoad);
//            }

            if (extra_signature_fileSignatureManage != null) {

                LogUtils.json(ConstantSign.LOGCAT_NOMAL + "这是详情携带的数据--extra_signature_fileSignatureManage", extra_signature_fileSignatureManage);

//                informationId_upLoad = extra_signature_fileSignatureManage.getInformationId();

                //获取客户信息用到的内容
//                vehicleType_upLoad = extra_signature_fileSignatureManage.getVehicleType();

                //主要的是携带手机号信息
                clientPhone_upLoad = extra_signature_fileSignatureManage.getClientPhone();

//                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "这是详情携带的数据--extra_signature_fileSignatureManage", informationId_upLoad);


//                {
//                    "auditStatus": "0",
//                        "businessTypeName": null,
//                        "catalogName": null,
//                        "clientName": "",
//                        "clientPhone": "13893847583",
//                        "communityName": "长安国际汽车产业园",
//                        "createSerialNo": null,
//                        "createTime": "2023-11-27 11:25:56",
//                        "informationId": "48",
//                        "informationNo": "170105555654981547",
//                        "managerId": "0",
//                        "shopInfoName": "特斯拉体验店",
//                        "signTaskId": null,
//                        "signTemplateId": null,
//                        "signTemplateName": null,
//                        "vehicleType": "0"
//                }

            }

        }


    }
}